/*              Copyright(c) 2008 Dave Sexton              *
 * http://www.codeplex.com/DocProject                      *
 * http://www.codeplex.com/DocProject/Project/License.aspx *
 ***********************************************************/
using System;
using System.Collections.Generic;
using System.Text;

namespace DaveSexton.Sandcastle
{
	public struct UrlMapping : IEquatable<UrlMapping>
	{
		#region Public Properties
		public string Id
		{
			get
			{
				return id;
			}
		}

		public Uri Href
		{
			get
			{
				return href;
			}
		}
		#endregion

		#region Private / Protected
		private readonly string id;
		private readonly Uri href;
		#endregion

		#region Constructors
		/// <summary>
		/// Constructs a new instance of the <see cref="UrlMapping" /> structure.
		/// </summary>
		public UrlMapping(string id, string href)
		{
			if (string.IsNullOrEmpty(id))
				throw new ArgumentException(Resources.Errors.NullOrEmpty, "id");
			
			this.id = id;
			this.href = (href == null) ? null : new Uri(href, UriKind.RelativeOrAbsolute);
		}

		/// <summary>
		/// Constructs a new instance of the <see cref="UrlMapping" /> structure.
		/// </summary>
		public UrlMapping(string id, Uri href)
		{
			if (string.IsNullOrEmpty(id))
				throw new ArgumentException(Resources.Errors.NullOrEmpty, "id");

			this.id = id;
			this.href = href;
		}
		#endregion

		#region Methods
		public override bool Equals(object obj)
		{
			return obj is UrlMapping && Equals((UrlMapping) obj);
		}

		public override int GetHashCode()
		{
			return (id ?? "").GetHashCode();
		}

		public override string ToString()
		{
			return id;
		}

		public static bool operator ==(UrlMapping map1, UrlMapping map2)
		{
			return map1.Equals(map2);
		}

		public static bool operator !=(UrlMapping map1, UrlMapping map2)
		{
			return !map1.Equals(map2);
		}
		#endregion

		#region IEquatable<UrlMapping> Members
		public bool Equals(UrlMapping other)
		{
			return string.Equals(id, other.id, StringComparison.OrdinalIgnoreCase);
		}
		#endregion
	}
}
